<?php

namespace App\Admin\Controllers;

use App\Models\MainBusiness;
use App\Models\Unit;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;

class MainBusinessController extends AdminController
{
    protected  $model = MainBusiness::class;
    protected function title()
    {
        return '主营业务';
    }
    protected function grid()
    {
        $grid = new Grid(new $this->model);

        $grid->filter(function (Grid\Filter $filter) {
            $filter->disableIdFilter(); //去掉默认的id过滤器

            $filter->like('name', trans('unit.name'));
        });

        //$grid->disableExport();

        $grid->model()->orderBy('sort');
        $grid->column('name', '业务名称');

        $grid->column('created_at', trans('unit.created_at'));
        $script = <<<EOT

var search = $('.btn-dropbox');
search.hide();
EOT;
        Admin::script($script);
        return $grid;
    }


    protected function form()
    {
        $form = new Form(new $this->model);

        $form->text('name', '业务名称')->rules('required');
        $form->switch('status', trans('admin.status'))->default(1);

        return $form;
    }

}
